<?php
class ChangepwdForm extends CFormModel{

	public $username;	//用户名
	public $password;	//密码
	public $newpassword;	//新密码
	public $renewpassword;	//重复输入一次新密码

	public function attributeLabels(){
		return array(
			'username'=>'用户名',
			'password'=>'密码',
			'newpassword'=>'新密码',
			'renewpassword'=>'新密码确认'
			);
	}

	public function rules(){
		return array(
			array('username', 'required', 'message'=>'用户名不能为空'),
			array('password', 'required', 'message'=>'密码不能为空'),
			array('newpassword,renewpassword', 'required', 'message'=>'新密码不能为空'),
			array('renewpassword', 'compare', 'compareAttribute'=>'newpassword', 'message'=>'两次密码输入不一致'),
			array('password', 'checkPwd')
			);
	}

	public function checkPwd(){
		$userInfo = User::model()->findByAttributes(array('username'=>$this->username));
		if(md5($this->password) != $userInfo['password']){
			$this->addError('password', '原密码错误');
		}
	}
}